package cn.com.web.Servlet;

import cn.com.domain.Customer;
import cn.com.service.CustomerService;
import cn.com.service.impl.CustomerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/AddCustomerServlet")
public class AddCustomerServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String customer_name = request.getParameter("customer_name");
        String identity_num = request.getParameter("identity_num");
        String sex = request.getParameter("sex");
        String phone = request.getParameter("phone");
        Customer customer=new Customer(null,identity_num,sex,phone,customer_name);
        CustomerService service=new CustomerServiceImpl();
        service.addCustomer(customer);
        //返回到查询页面
        request.getRequestDispatcher("FindCustomerByPageServlet?currentPage=1&rows=5")
                .forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
